﻿using System.ComponentModel;

namespace TallyMarks.Models
{
    public class TallyModel : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        private int _count;

        public int Count
        {
            get { return _count; }
            set
            {
                if (!IsValid(value)) return;
                _count = value;
                FirePropertyChanged();
            }
        }

        private static bool IsValid(int value)
        {
            return value >= 0;
        }

        private void FirePropertyChanged()
        {
            if (PropertyChanged != null)
            {
                PropertyChanged.Invoke(
                    this,
                    new PropertyChangedEventArgs("Count"));
            }
        }
    }
}
